<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="交易号" prop="txJyid">
        <el-input
          v-model="queryParams.txJyid"
          placeholder="请输入交易号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="申请人" prop="txName">
        <el-input
          v-model="queryParams.txName"
          placeholder="请输入申请人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="提现方式" prop="txTixianfangshi">
        <el-input
          v-model="queryParams.txTixianfangshi"
          placeholder="请输入提现方式"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="银行卡号" prop="txYinhangkahao">
        <el-input
          v-model="queryParams.txYinhangkahao"
          placeholder="请输入银行卡号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预留手机号" prop="txYuliuphone">
        <el-input
          v-model="queryParams.txYuliuphone"
          placeholder="请输入预留手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="提现金额" prop="txTixianmoney">
        <el-input
          v-model="queryParams.txTixianmoney"
          placeholder="请输入提现金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="打款金额" prop="txDakuanmoney">
        <el-input
          v-model="queryParams.txDakuanmoney"
          placeholder="请输入打款金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="申请时间" prop="txShenqintime">
        <el-date-picker clearable
          v-model="queryParams.txShenqintime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择申请时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="处理时间" prop="txChulitime">
        <el-date-picker clearable
          v-model="queryParams.txChulitime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择处理时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="状态" prop="txZhuangtai">
        <el-select v-model="queryParams.txZhuangtai" placeholder="请选择状态" clearable>
          <el-option
            v-for="dict in dict.type.zh_tx_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['caiwu:tixian:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['caiwu:tixian:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['caiwu:tixian:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['caiwu:tixian:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="tixianList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="提现ID" align="center" prop="txId" />-->
      <el-table-column label="交易号" align="center" prop="txJyid" />
      <el-table-column label="申请人" align="center" width="130">
        <template slot-scope="scope">
          <div class="shenqing">
            <p style="color: black;margin: 0;padding: 0">{{scope.row.txName}}</p>
            <p style="color: #bbbbbb;margin: 0;padding: 0">+86{{scope.row.txYuliuphone}}</p>
          </div>

        </template>
      </el-table-column>
      <el-table-column label="提现方式" align="center" prop="txTixianfangshi"/>

      <el-table-column label="银行卡号" align="center" width="180">
        <template slot-scope="scope">
          <div class="shenqing">
            <p style="color: black;margin: 0;padding: 0">{{scope.row.txYinhangkahao}}</p>
            <p style="color: #bbbbbb;margin: 0;padding: 0">{{scope.row.txKaihuyinghang}}</p>
          </div>

        </template>
      </el-table-column>
      <el-table-column label="预留手机号" align="center" prop="txYuliuphone" width="120"/>
      <el-table-column label="提现金额" align="center" prop="txTixianmoney" />
      <el-table-column label="打款金额" align="center" width="100">
        <template slot-scope="scope">
          <p style="color: black;margin: 0;padding: 0">￥{{scope.row.txDakuanmoney}}</p>
          <p style="color: #bbbbbb;margin: 0;padding: 0">(手续费:￥{{scope.row.txShouxufei}})</p>
        </template>
      </el-table-column>
      <el-table-column label="申请时间" align="center" prop="txShenqintime" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.txShenqintime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="处理时间" align="center" prop="txChulitime" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.txChulitime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="txZhuangtai">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.zh_tx_status" :value="scope.row.txZhuangtai"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['caiwu:tixian:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['caiwu:tixian:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改提现管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="交易号" prop="txJyid">
          <el-input v-model="form.txJyid" placeholder="请输入交易号" />
        </el-form-item>
        <el-form-item label="申请人" prop="txName">
          <el-input v-model="form.txName" placeholder="请输入申请人" />
        </el-form-item>
        <el-form-item label="提现方式" prop="txTixianfangshi">
          <el-input v-model="form.txTixianfangshi" placeholder="请输入提现方式" />
        </el-form-item>
        <el-form-item label="开户银行" prop="txKaihuyinghang">
          <el-input v-model="form.txKaihuyinghang" placeholder="请输入开户银行" />
        </el-form-item>
        <el-form-item label="银行卡号" prop="txYinhangkahao">
          <el-input v-model="form.txYinhangkahao" placeholder="请输入银行卡号" />
        </el-form-item>
        <el-form-item label="预留手机号" prop="txYuliuphone">
          <el-input v-model="form.txYuliuphone" placeholder="请输入预留手机号" />
        </el-form-item>
        <el-form-item label="提现金额" prop="txTixianmoney">
          <el-input v-model="form.txTixianmoney" placeholder="请输入提现金额" />
        </el-form-item>
        <el-form-item label="手续费" prop="txShouxufei">
          <el-input v-model="form.txShouxufei" placeholder="请输入手续费" />
        </el-form-item>
        <el-form-item label="打款金额" prop="txDakuanmoney">
          <el-input v-model="form.txDakuanmoney" placeholder="请输入打款金额" />
        </el-form-item>
        <el-form-item label="申请时间" prop="txShenqintime">
          <el-date-picker clearable
            v-model="form.txShenqintime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择申请时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="处理时间" prop="txChulitime">
          <el-date-picker clearable
            v-model="form.txChulitime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择处理时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="状态" prop="txZhuangtai">
          <el-radio-group v-model="form.txZhuangtai">
            <el-radio
              v-for="dict in dict.type.zh_tx_status"
              :key="dict.value"
              :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listTixian, getTixian, delTixian, addTixian, updateTixian } from "@/api/caiwu/tixian";

export default {
  name: "Tixian",
  dicts: ['zh_tx_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 提现管理表格数据
      tixianList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        txJyid: null,
        txName: null,
        txKaihuyinhang:null,
        txTixianfangshi: null,
        txYinhangkahao: null,
        txYuliuphone: null,
        txTixianmoney: null,
        txDakuanmoney: null,
        txShenqintime: null,
        txChulitime: null,
        txZhuangtai: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        txJyid: [
          { required: true, message: "交易号不能为空", trigger: "blur" }
        ],
        txName: [
          { required: true, message: "申请人不能为空", trigger: "blur" }
        ],
        txTixianfangshi: [
          { required: true, message: "提现方式不能为空", trigger: "blur" }
        ],
        txYinhangkahao: [
          { required: true, message: "银行卡号不能为空", trigger: "blur" }
        ],
        txYuliuphone: [
          { required: true, message: "预留手机号不能为空", trigger: "blur" }
        ],
        txTixianmoney: [
          { required: true, message: "提现金额不能为空", trigger: "blur" }
        ],
        txDakuanmoney: [
          { required: true, message: "打款金额不能为空", trigger: "blur" }
        ],
        txShenqintime: [
          { required: true, message: "申请时间不能为空", trigger: "blur" }
        ],
        txZhuangtai: [
          { required: true, message: "状态不能为空", trigger: "change" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询提现管理列表 */
    getList() {
      this.loading = true;
      listTixian(this.queryParams).then(response => {
        this.tixianList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        txId: null,
        txJyid: null,
        txName: null,
        txTixianfangshi: null,
        txYonghutype: null,
        txKaihuyinghang: null,
        txYinhangkahao: null,
        txYuliuphone: null,
        txTixianmoney: null,
        txShouxufei: null,
        txDakuanmoney: null,
        txShenqintime: null,
        txChulitime: null,
        txZhuangtai: null,
        txCaozuo: null,
        zfJyid: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.txId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加提现管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const txId = row.txId || this.ids
      console.log(txId)
      getTixian(txId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改提现管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.txId != null) {
            updateTixian(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTixian(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const txIds = row.txId || this.ids;
      this.$modal.confirm('是否确认删除提现管理编号为"' + txIds + '"的数据项？').then(function() {
        return delTixian(txIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('caiwu/tixian/export', {
        ...this.queryParams
      }, `tixian_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style>
.shenqing {
  text-align: left !important;
}
</style>
